Previous Book Contents Book Index Next

Inside Macintosh: QuickDraw GX Objects /
Chapter 6 - Transform Objects / Using Transform Objects


Manipulating the View Port List

The view port list property of the transform object specifies all the view ports to
which shapes associated with the transform are drawn. QuickDraw GX provides a pair of functions (GXGetTransformViewPorts and GXSetTransformViewPorts)
that get and set the view port list of a specified transform, and another pair (GXGetShapeViewPorts and GXSetShapeViewPorts) that get and set the
view port list of the transform associated with a specified shape. View ports are described in the chapter "View-Related Objects" in this book.

When you create a window, you create one or more view ports. If you want the shapes that you subsequently create to be drawn in that window, you place references to one or more of those view ports in the view port list of the shapes' transform object.

You may also want to alter a view port list of an existing transform object. For example, you might temporarily create a pane or a separate window that shows a zoomed view of a currently displayed shape. As another example, you might want to draw an object both onscreen and offscreen simultaneously.

Listing 6-6 is a partial listing of a function that adds a new view port (newPort) to
the view port list of the transform object myTransform. The function calls the GXGetTransformViewPorts function twice, first to determine the number of view ports already in the list in order to allocate memory for it, and second to retrieve the list itself. Before adding the new view port, the function first checks the list and, if the view port is already in the list, does not add it. The function assigns the new view port to the last element in the list, and then calls GXSetTransformViewPorts to reassign the list to the transform. Finally, the code disposes of the view port list.

Listing 6-6 Getting and setting view ports

gxViewPort     *ports, *portPtr;
gxViewPort     newPort;
short          portCount, count;
gxTransform    myTransform;
.
.  /* get the transform, set up the new view port (not shown) */
.
/* first, call to see how big the current view port list is */
portCount = GXGetTransformViewPorts(myTransform, nil);

/* accounting for new view port, allocate memory for the list */
portCount++;
ports = (gxViewPort *) NewPtr(portCount * sizeof(gxViewPort));

/* get the current list into memory */
GXGetTransformViewPorts(myTransform, ports);

/* check if the view port is already in the list */
portPtr = ports;
count = portCount;
while (--count > 0)         
{
   /* if port is already in transform, release memory and leave */
   if (*portPtr++ == newPort) 
   {
      DisposPtr((void *) ports);
      return;
   }
}
/* put view port in transform */
*portPtr = newPort;
GXSetTransformViewPorts(myTransform, portCount, ports);

/* clean up and leave */
DisposePtr((void *)ports);
return;
The GXGetTransformViewPorts function is described on page 6-73;
the GXSetTransformViewPorts function is described on page 6-74. The GXGetShapeViewPorts function is described on page 6-75;
the GXSetShapeViewPorts function is described on page 6-76.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
7 JUL 1996